package br.com.fsa.aplication.Database;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import br.com.fsa.aplication.Exception.ConectionException;
import br.com.fsa.aplication.Model.bean.Log;
import br.com.fsa.aplication.Model.bean.TipoLog;
import br.com.fsa.aplication.Model.bean.Usuario;
import br.com.fsa.aplication.Util.HibernateUtil;
import br.com.fsa.aplication.Util.Util;

public class LogDAO extends DaoGenericoImpl<Log>
{

	public int getQtdLog(TipoLog _tipo, int _ano, int _mes, long _log)
			throws ConectionException
	{
		int retorno = 0;

		Session session = null;
		try
		{
			session = HibernateUtil.getSession().openSession();

			Query query = session
					.createQuery("from Log where month(data) = :mes and year(data) = :ano and TipoLog = :tipo and clienteID = :log");
			query.setParameter("mes", _mes);
			query.setParameter("ano", _ano);
			query.setParameter("tipo", _tipo);
			query.setParameter("log", _log);

			retorno = query.list().size();
		} catch (HibernateException e)
		{
			Util.gravaLog(e.getMessage());
			throw new ConectionException(e.getMessage());

		} catch (Exception erro)
		{
			System.out.println(erro.getMessage());
		} finally
		{
			if (session.isOpen())
			{
				session.close();
			}

		}
		return retorno;

	}

}
